package com.timing.finder.framework;

import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;

/**
 * 缓存存储库
 *
 * @author JingGe(* ^ ▽ ^ *)
 * @date 2023-03-03 10:41
 * @email 1158055613@qq.com
 */
public interface CacheRepository extends Repository {

    String formatKey(String key);

    <T> boolean set(String key, T value);

    <T> boolean set(String key, T value, long expiringTime, TimeUnit unit);

    <T> T get(String key, Class<T> type);

    long alloc(String key, long size);

    boolean isExist(String key);

    boolean createKeyListIfAbsent(String key, long startOffset, long size, long expiringTime, TimeUnit unit);

    boolean createKeyListsIfAbsent(Map<String, Long> keyMap, long startOffset, long expiringTime, TimeUnit unit);

    /**
     * 批量实现桶的创建和值的导入
     *
     * @param keyMap       (桶名，初始化长度)
     * @param valueEntries 值
     * @param startOffset  起始偏移
     * @param expiringTime 桶过期时间
     * @param unit         时间单位
     * @return int
     * @author JingGe(* ^ ▽ ^ *)
     * @date 2023/3/8 14:12
     */
    <R extends TimeSeriesData> int loadBatch(Map<String, Long> keyMap, List<ValueEntry<R>> valueEntries, long startOffset, long expiringTime, TimeUnit unit);

    Map<String, Boolean> scanKeysExist(List<String> keys);

    Set<String> scanPatternKeys(String pattern);

    long deletePattern(String pattern);

    long startOffset(String key);

    <R extends TimeSeriesData> boolean indexSet(String key, long index, R value);

    <R extends TimeSeriesData> int indexSets(String key, Map<Long, R> values);

    <T extends CacheData> T index(String key, long index, Class<T> type);

    <T extends CacheData> List<T> range(String key, long start, long end, Class<T> type);

    long size(String key);

}
